package com.test.loop;

public class ForTest2 {
    public static void main(String[] args) {
        //目标：完成1~5的求和
        System.out.println("1~5的和为：" + test1(5));
        //目标：完成1~10的偶数求和
        System.out.println("1~10的偶数和为：" + test2(10));
        //目标：完成1~10的奇数求和
        System.out.println("1~10的奇数和为：" + test3(10));
    }

    public static int test1(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += i;
        }
        return sum;
    }

    public static int test2(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 2 == 0) {
                sum += i;
            }
        }
        return sum;
    }

    public static int test3(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 2 == 1) {
                sum += i;
            }
        }
        return sum;
    }
}
